package com.dh.bm.dao.impl;

import com.dh.bm.common.JDBCUtil;
import com.dh.bm.dao.BookDao;
import com.dh.bm.entity.Book;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BookDaoImpl implements BookDao {
    @Override
    public List<Book> queryAll() {
        String sql = "select * from book";
        PreparedStatement ps = JDBCUtil.getStatement(sql);
        try {
            ResultSet resultSet = ps.executeQuery();
            List<Book> books = new ArrayList<>();
            while (resultSet.next()) {
                int id = resultSet.getInt(1);
                String name = resultSet.getString(2);
                Book book = new Book(id, name);
                books.add(book);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

    @Override
    public Book queryById(int id) {
        return null;
    }

    @Override
    public boolean update(Book book, int id) {
        return false;
    }

    @Override
    public boolean delete(int id) {
        return false;
    }

    @Override
    public boolean insert(Book book) {
        return false;
    }
}
